import React, { useState, createContext } from 'react'
import ChildrenCom from './Demo5'

export const CountContext = createContext()

export const Demo4 = () => {
    const [obj, setCount] = useState({ name: 'test', count: 0 })

    const handleSetCount = () => {
        setCount({ ...obj, count: obj.count + 1 })
    }

    return (
        <div>
            <p>父组件：当前数值 {obj.count} </p>
            <button onClick={handleSetCount}>加</button>
            <CountContext.Provider value={obj}>
                <ChildrenCom></ChildrenCom>
            </CountContext.Provider>
        </div>
    )
}
